package com.lt.bcra.result;

import lombok.Data;

@Data
public class ResultData<T> {
    private Integer code;
    private String message;
    private T body;


    /**
     * 返回数据状态
     * @return
     */
    public void setStatus(ResponseEnum responseEnum) {
        this.code=responseEnum.getCode();
        this.message=responseEnum.getMessage();
    }

    /**
     * 统一数据返回状态
     * @param object
     * @return
     */
    public static ResultData getResult(Object object) {
        ResultData resultData = new ResultData<>();
        if (object != null) {
            resultData.setBody(object);
            resultData.setStatus(ResponseEnum.SUCCESS);
        } else {
            resultData.setStatus(ResponseEnum.FAIL);
        }
        return resultData;
    }
}
